<template>
  <Landscape horizontal>
    <div class="search-thumb" :style="{'padding-left':statusBarHeight+'px'}">
      <svg-icon icon-class="xiangzuo" @click.native.stop="clickLeftHandle" />
      <div>
        <SearchInput v-model="searchValue" placeholder="图片名称" />
      </div>
    </div>
    <div slot="scroll" class="thumb-atlas">
      <div class="child-atlas">
        <div v-for="(p,i) in srcList" :key="i" class="col">
          <div class="list-child-atlas-item" @click.stop="cilckHandle(p)">
            <ImageVideo class="list-child-atlas-item-img" fit="fill" :src="p.src" />
            <div class="list-child-atlas-item-name">{{ p.name }}</div>
          </div>
        </div>
      </div>
    </div>
  </Landscape>
</template>
<script>
import Landscape from '@/components/Landscape'
import SearchInput from '@/components/SearchInput'
import ImageVideo from '@/components/ImageVideo'
import { getListByAtlasId } from '@/apis/atlas'
import { mapGetters } from 'vuex'
export default {
  name: 'AtlasLastPreviewThumb',
  components: {
    Landscape,
    SearchInput,
    ImageVideo
  },
  props: {
    id: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      searchValue: '',
      list: []
    }
  },
  computed: {
    ...mapGetters(['statusBarHeight']),
    srcList() {
      if (this.searchValue === '') return this.list
      const reg = new RegExp(this.searchValue)
      return this.list.filter(e => {
        return reg.test(e.name)
      })
    }
  },
  created() {
    this.getData()
  },
  beforeRouteLeave(to, from, next) {
    if (to.name !== 'AtlasLastPreview') {
      this.$removeKeepAliveCache(this)
    }
    next()
  },
  methods: {
    getData() {
      getListByAtlasId(this.id).then(res => {
        this.list = res.data.map((e, i) => {
          e.src = e.smallUrl
          e.type = 'image'
          e.name = e.fileName
          e._index = i
          return e
        })
      })
    },
    clickLeftHandle() {
      this.$router.go(-1)
    },
    // 预览
    cilckHandle(p) {
      sessionStorage.setItem('atlas_index', p._index)
      this.$router.replace({ name: 'AtlasLastPreview', params: { id: this.id }, query: { atlasName: this.$route.query.atlasName }})
    }
  }
}
</script>
<style lang="less" scoped>
  .search-thumb{
    // position: fixed;
    // top: 0px;
    display: flex;
    width: 100%;
    height: 50px;
    z-index: 999;
    align-items: center;
    padding: 10px 20px;
    background-color: rgba(64, 64, 64, 1);
    box-sizing: border-box;
    &>svg{
      color: #fff;
      fill: #fff;
      font-size: 24px;
      flex: 0 0 25px;
    }
    &>div{
      flex: 1 0 auto;
    }
  }
.thumb-atlas{
  // padding-top: 50px;
  .child-atlas{
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    background-color: #F5F6F7;
    box-sizing: border-box;
    width: 100vh;
    @gutter:12px;
    margin: 0 -@gutter/2;
    .col{
      padding: 0 @gutter/2;
      flex: 0 1 25%;
      box-sizing: border-box;
      overflow: hidden;
    }
    .list-child-atlas-item{
      margin-bottom: 10px;
      // height: 223px;
      padding: 5px 5px 10px 5px;
      box-sizing: border-box;
      background-color: white;
      .list-child-atlas-item-img{
        width: 100%;
        height: 90px;
      }
      .list-child-atlas-item-name{
        font-size: 14px;
        color: #333;
        height: 20px;
        line-height: 20px;
        text-align: center;
        margin-top: 10px;
        font-weight: normal;
        .textOverflow(100%)
      }
    }
  }
}
</style>
